<template>
	<!-- 名片 -->
	<view class="business" :style="{height: windowHeight+'px'}">
		<view class="business_info">
			<view class="business_head">
				<image class="business_avator" v-if="userInfo.avatar" :src="photo_cdn1+userInfo.avatar"></image>
				<image class="business_avator" v-else-if="userInfo.gender==1" :src="photo_cdn1+'zpupload/static/tablet/boy_alive.png'" mode=""></image>
				<image class="business_avator" v-else :src="photo_cdn1+'zpupload/static/tablet/girl_alive.png'" mode=""></image>
				<view>
					<view class="business_name">{{userInfo.nickname}}</view>
					<view class="business_name" v-if="addr_name.city">{{addr_name.city}}</view>
				</view>
			</view>
			<view class="business_qrcode flexc">
				
				<!-- <image class="qrcode_card"></image> -->
				
				<!-- #ifndef MP-ALIPAY -->
				<canvas class="tki-qrcode-canvas"  canvas-id="tki-qrcode-canvas" :style="{width:cpSize+'px',height:cpSize+'px'}" />
				<!-- #endif -->
				<!-- #ifdef MP-ALIPAY -->
				<canvas id="tki-qrcode-canvas" :width="cpSize" :height="cpSize" class="tki-qrcode-canvas" />
				<!-- #endif -->
				
			</view>
			<view class="explain">扫一扫上面的二维码图案，加我为好友</view>
		</view>
	</view>
</template>

<script>
	import {getUserinfo} from "@/utils/api/api.js";
	import config from "@/utils/config.js";
	let {staticurl,photo_cdn1} = config.baseUrl;
	
	import QRCode from "@/components/tki-qrcode/qrcode.js"
	let qrcode;
	export default{
		data(){
			return{
				staticurl,
				photo_cdn1,
				windowHeight:0,
				userInfo: {addr_name:{}},
				
				
				poster: {},
				qrShow: false,
				canvasId: 'default_PosterCanvasId',
				qrcode_url:"",//二维码路径
				// 二维码
				cpSize:200,
				result:"",
				//城市名称
				addr_name:{
					city:null
				}
			}
		},
		onReady(){
			this.computeheight()
		},
		onShow() {
			let token = uni.getStorageSync("token")
			if (!token) {
				// #ifdef MP-WEIXIN
				setTimeout(() => {
					this.isshowlogin = true;
				}, 1500)
				// #endif
			} else {
				this.getUserinfofun();
			}
		},
		methods:{
			//画二维码
			demoimgs(){
				let that = this
				// transparent
				qrcode = new QRCode({
					context: that, // 上下文环境
					canvasId:"tki-qrcode-canvas", // canvas-id
					usingComponents: true,//that.usingComponents, // 是否是自定义组件
					showLoading: false,//that.showLoading, // 是否显示loading
					loadingText: "",//that.loadingText, // loading文字
					text: `https://zp.xicheda.com/qrcode?type=1&imuser_id=${this.userInfo.imuser_id}`, // 生成内容
					size: 200, // 二维码大小
					background: "#28AD6B", // 背景色 #ffffff
					foreground: "#ffffff", // 前景色 #000000
					pdground: "#ffffff", // 定位角点颜色 #000000
					correctLevel: 3, // 容错级别
					image: "",//this.userInfo.face,//that.icon, // 二维码图标
					imageSize: 30,//that.iconSize,// 二维码图标大小
					cbResult:  (res)=> { // 生成二维码的回调
						this.result = res;
					},
				})
			},
			computeheight(){
				let resinfo = uni.getSystemInfoSync();
				this.windowHeight = resinfo.windowHeight;
			},
			getUserinfofun() {
				let that = this;
				getUserinfo({}).then((res) => {
					that.userInfo = null;
					that.userInfo = res.data.userinfo;
					if(res.data.userinfo.addr_name != null){
						this.addr_name = res.data.userinfo.addr_name;
					}
					uni.setStorageSync("u_userInfo", res.data.userinfo);
					that.demoimgs();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./business_card.scss"
	
</style>